using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;
using PageFlowQuickstart.Modules.Customers.BusinessEntities;

namespace PageFlowQuickstart.Modules.Customers.Views
{
    public class SummaryViewPresenter : Presenter<ISummaryView>
    {
        private CustomersController _controller;
        
        public SummaryViewPresenter([CreateNew] CustomersController controller)
        {
            _controller = controller;
        }

        public override void OnViewInitialized()
        {
            Customer customer = _controller.CurrentCustomer;
            if (customer != null)
            {
                View.Customer = _controller.CurrentCustomer;
                _controller.FinishCustomerApproval();
            }
            else
            {
                _controller.StartCustomerApproval();
            }
        }

        public void OnApproveAnotherCustomer()
        {
            _controller.StartCustomerApproval();
        }
    }
}
